home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d1 / bastips2.arc / BASTIME.TXT < prev    next >
Encoding:
Text File  |  1988-11-30  |  3.1 KB  |  65 lines

  1.                        Split-Second Timing
  2.               (PC World October 1986 Star-Dot-Star)
  3.  
  4.      System clock time accurate to 1/100 second is possible with a
  5. pinch of BASIC and some help from DOS.  With such a stopwatch, you
  6. can, for example, generate far more exact benchmarks.  Unfortunately,
  7. BASIC's reserved variable TIME$ will not return fractions of a second,
  8. effectively preventing BASIC routines from being time this precisely.
  9.      The machine language subroutine demonstarted by 100THS.BAS enables
  10. BASIC to read the hundredths-of-a-second values kept by DOS and to
  11. display them on screen.  The program puts the subroutine into memory
  12. and executes it with BASIC's CALL command.
  13.      The format for calling the subroutine is CALL TIME(hours, minutes,
  14. seconds, hundredths), where hours, minutes, seconds, and hundredths are
  15. integer variables to which the corresponding values will be passed.
  16. You must include a variable for each value, and all four variables must
  17. be integer type.
  18.  
  19. 100 '100THS.BAS
  20. 110 DEF SEG:DEFINT A-Z:DEFSNG T:KEY OFF:CLS
  21. 120 'Function to add leading zeros to values
  22. 130 DEF FNA$(X)=RIGHT$("0"+MID$(STR$(X),2,2),2)
  23. 140 'Place subroutine into memory
  24. 150 FOR I=1 TO 31
  25. 160 READ CODE$
  26. 170 PRG$=PRG$+CHR$(VAL("&H"+CODE$))
  27. 180 NEXT
  28. 190 'Call the subroutine
  29. 200 TPTR=VARPTR(PRG$)
  30. 210 TIME=PEEK(TPTR+1)+(256*PEEK(TPTR+2))
  31. 220 CALL TIME(HRS,MIN,SEC,HND)
  32. 230 'Add leading zeros and display the time
  33. 240 HR$=FNA$(HRS):MN$=FNA$(MIN)
  34. 250 SC$=FNA$(SEC):HN$=FNA$(HND)
  35. 260 LOCATE 12,15,0
  36. 270 PRINT HR$+":"+MN$+":"+SC$+"."+HN$
  37. 280 GOTO 200
  38. 290 'Data for the machine language subroutine
  39. 300 DATA 55,8b,ec,b4,2c,cd,21,8b,5e,0c,88,2f,8b,5e,0a,88
  40. 310 DATA 0f,8b,5e,08,88,37,8b,5e,06,88,17,5d,ca,08,00
  41.  
  42. -----------------------------------------------------------------
  43.             Does Anybody Really Know What Time It Is?
  44.             (PC World The Help Screen December 1986)
  45.  
  46.      A programmer is trying to write a routine in BASIC for a program
  47. that will permit time operations with greater precision than that
  48. offered by the reserved variable TIME$.  (TIME$ returns values only to
  49. the nearest minute.)  By PEEKing into offsets 1132, 1133, and 1134 of
  50. segment 0 (DEF SEG = 0), a routine with a precision of about six one-
  51. hundredths of a minute is possible.  Is there a mthod that does not use
  52. PEEKs and is more precise?
  53.      You can use DOS function 2C hex by MOVing the value 2C into
  54. register AH (MOV AH,2C) and calling interrupt 21 hex (INT 21) to obtain
  55. time with a precision of one-hundredth of a second.  On return,
  56. register CH will contain the hours (0 through 23), CL will contain the
  57. minutes (0 through 59), DH the seconds (0 through 59), and DL the
  58. hundredths of a second (0 through 99).  However, BASIC 2.0's TIMER
  59. function is easier to use than DOS function 2C and yields results just
  60. as precise.  TIMER is a read-only variable containing the number of
  61. seconds (to the nearest hundredth) since midnight or system reset.
  62. Programs using the TIMER function can be compiled with IBM's BASIC
  63. Compiler 2.00 or with Microsoft's QuickBASIC Compiler.
  64.  
  65.